/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.Produccion;

/**
 *
 * @author Nadhia
 */
import Atxy2k.CustomTextField.RestrictedTextField;
import Controlador.Bean.Produccion.Maquina;
import Controlador.Bean.Produccion.TipoMaquina;
import gui.General.Main;
import java.awt.Component;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import lib.Validaciones;

public class agregarMaquina extends javax.swing.JInternalFrame {

    /**
     * Creates new form agregarMaquina
     */
    private List<Maquina> tipos;
    List<Maquina> datos;
    private TableModel tb;
    int clic=0;
    String selectedId;
    Date today;
    Date fecha;
    public agregarMaquina() {
        today = new Date();
        initComponents();
        initComp();
    }
    
    private static agregarMaquina myoc=null;
    public static  agregarMaquina getInstance(){
        if (myoc == null){
             myoc = new agregarMaquina();
             Main.getDesktop().add(myoc);
             myoc.setVisible(true);
             myoc.toFront();
            }
        else {
            if(myoc.isClosed()|| !myoc.isVisible()){
                myoc = new agregarMaquina();
                Main.getDesktop().add(myoc);
                myoc.toFront();
                myoc.setVisible(true);
                }
            else myoc.toFront();
        }
           
        
        return myoc;
    }
    
    
    
    private void initComp(){
         datos = Controlador.Service.Produccion.GestionProduccion.obtenerMaquinas();
         tb = new TableModel();
         tblMaquinas.setModel(tb);
         tblMaquinas.setRowSelectionAllowed(true);
         txtIdMaquina.setEditable(false);
         jdpFecha.setDate(today);
         tipos = Controlador.Service.Produccion.GestionProduccion.obtenerTipo();
         cmbTipo.removeAllItems();
//         cmbUnidadMedida.removeAllItems();
//         cmbUnidadMedida.addItem("Seleccionar");
//         cmbUnidadMedida.addItem("Kg.");
//         cmbUnidadMedida.addItem("m.");
//         cmbUnidadMedida.addItem("gr.");
//         cmbUnidadMedida.addItem("Unidades");
         cmbTipo.addItem("Seleccionar");
         for(int i=0; i<tipos.size(); i++){
             cmbTipo.addItem(tipos.get(i).getNombre());
         }
         tblMaquinas.setDefaultRenderer(JButton.class, new MiRender());
         tblMaquinas.setDefaultEditor( JButton.class, new MiEditor());
         btnBuscar.setMnemonic(KeyEvent.VK_F2);
         RestrictedTextField restricted = new RestrictedTextField(txtNombre);
         restricted.setLimit(50);
//         restricted.setOnlyText(true);
         
     }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    String id  = "";
    String nombre = "";
    
    public void filtrar(String id, String nombre){
        this.id = id;
        this.nombre = nombre;
        tb.actualizarTabla();
    }
    
    
    class TableModel extends AbstractTableModel{
        
        //Two arrays used for the table data
        String[] columnNames = {"Código", "Nombre", "Descripción",
                         "Tipo", "Fecha", "Eliminar"};
               
        public List<Maquina> data = datos;
        
        
        public void actualizarTabla(){
            data = Controlador.Service.Produccion.GestionProduccion.filtrarMaquinas(id, nombre);
            fireTableDataChanged();
            id="";
            nombre="";
        }
        
        @Override
        public int getRowCount()
        {
            return data.size();
        }
        
        
        
        @Override
        public int getColumnCount()            
        {
            return columnNames.length;
        }
        
        @Override
        public Object getValueAt(int row, int column)
        {   
            switch(column){
                case 0: return data.get(row).getIdMaquina();
                case 1: return data.get(row).getNombre(); 
                case 2: return data.get(row).getDescripcion();
                case 3: return data.get(row).getIdTipoMaquina();
                case 4: return data.get(row).getFechaAdq();
                default: return new JButton("Eliminar");
            }
        }
        
        //Used by the JTable object to set the column names
        @Override
        public String getColumnName(int column) {
            return columnNames[column];
        }
        
        //Used by the JTable object to render different
        //functionality based on the data type
        @Override
        public Class getColumnClass(int c) {
            if(c!=6){
            return getValueAt(0, c).getClass();
            }else{
                return JButton.class;
            }
        }
        
        @Override
        public boolean isCellEditable(int row, int column)
        {
	        return false;
        }
        
     }
    
    
    public class MiRender implements TableCellRenderer {
        // Este metodo indica como debe de pintarse el elemento en la fila row, en la columna column
        // que esta en la tabla table y tiene el color dado por el objeto.
        @Override
        public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) {    
            // como el boton y el calendario son componentes esto se vale.
            return (JComponent)table.getValueAt(row, column);
        }
     }
     
     public class MiEditor extends AbstractCellEditor implements TableCellEditor {
         private Boolean currentValue;
         @Override
         public Object getCellEditorValue()
         {
            return currentValue;
         }
         //El editor usara el propio componente. Para que funcione la celda en el modelo debe ser editable.
         @Override
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
         {
           return (JComponent) value;// la tabla solo debe tener componentes graficos
         }
     }
    
     
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlProducto = new javax.swing.JPanel();
        lblNombre = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        lblDescripcion = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtDescripcion = new javax.swing.JTextArea();
        lblUm = new javax.swing.JLabel();
        cmbTipo = new javax.swing.JComboBox();
        btnGuardar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txtIdMaquina = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jdpFecha = new org.jdesktop.swingx.JXDatePicker();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblMaquinas = new javax.swing.JTable();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setTitle("Agregar Maquina");
        setPreferredSize(new java.awt.Dimension(800, 489));

        pnlProducto.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalles del producto"));

        lblNombre.setText("Nombre:");

        lblDescripcion.setText("Descripción:");

        txtDescripcion.setColumns(10);
        txtDescripcion.setLineWrap(true);
        txtDescripcion.setRows(5);
        jScrollPane2.setViewportView(txtDescripcion);

        lblUm.setText("Tipo de Máquina:");

        cmbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTipoActionPerformed(evt);
            }
        });

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        jLabel1.setText("IdMaquina:");

        txtIdMaquina.setEditable(false);

        btnBuscar.setLabel("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        jLabel2.setText("Fecha de Adquisición:");

        jdpFecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jdpFechaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlProductoLayout = new javax.swing.GroupLayout(pnlProducto);
        pnlProducto.setLayout(pnlProductoLayout);
        pnlProductoLayout.setHorizontalGroup(
            pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlProductoLayout.createSequentialGroup()
                .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlProductoLayout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblNombre)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(21, 21, 21)
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                            .addComponent(txtIdMaquina)
                            .addComponent(jdpFecha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(125, 125, 125)
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblDescripcion)
                            .addComponent(lblUm))
                        .addGap(18, 18, 18)
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                            .addComponent(cmbTipo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(pnlProductoLayout.createSequentialGroup()
                        .addGap(159, 159, 159)
                        .addComponent(btnGuardar)
                        .addGap(82, 82, 82)
                        .addComponent(btnLimpiar)
                        .addGap(86, 86, 86)
                        .addComponent(btnBuscar)))
                .addContainerGap(46, Short.MAX_VALUE))
        );
        pnlProductoLayout.setVerticalGroup(
            pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProductoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlProductoLayout.createSequentialGroup()
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtIdMaquina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblNombre))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jdpFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(104, 104, 104))
                    .addGroup(pnlProductoLayout.createSequentialGroup()
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblUm)
                            .addComponent(cmbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDescripcion)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(pnlProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnBuscar)
                            .addComponent(btnLimpiar)
                            .addComponent(btnGuardar))
                        .addGap(37, 37, 37))))
        );

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        tblMaquinas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblMaquinas.setMinimumSize(new java.awt.Dimension(60, 20));
        tblMaquinas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblMaquinasMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblMaquinas);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addComponent(pnlProducto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public int validar(){
        int error = 0;
        int indice = (int)cmbTipo.getSelectedIndex();
        System.out.println("indice...."+indice);
        System.out.println("fecha...."+jdpFecha.getDate());
        if(txtNombre.getText().isEmpty()){
        error=1;}
        else if((jdpFecha.getDate()== null) || (jdpFecha.getDate().after(today))){
        error=2; }
        else if((indice==0))
        { error=3;  }
//        else if(txtDescripcion.getText().isEmpty()){
////        error=4;    
//        }
        
        return error;
        
        
    }
    
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        //String IdProducto, String IdTipoProducto, String UnidadMetrica, Double Cantidad, Double StockMinimo, String Descripcion, String Estado
        try {
        
        int error = validar();  
           
           if(error==1){
           JOptionPane.showMessageDialog(this,"Ingrese el nombre", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
               
           } else
           if(error==2){
               JOptionPane.showMessageDialog(this,"Ingrese la fecha", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           }
            else
               if(error==3){
               JOptionPane.showMessageDialog(this,"Selecciona el tipo", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           } 
//           else
//            if(error==4){
//               JOptionPane.showMessageDialog(this,"Ingrese una descripcion");
//           }  
           else
            if(error==0){
                
                 System.out.println("dato.."+cmbTipo.getSelectedIndex());
       //System.out.println("dato.."+cmbTipo.getSelectedIndex()-1);
        fecha = jdpFecha.getDate();
        Maquina nm = new Maquina(txtIdMaquina.getText(), txtNombre.getText(),  tipos.get(cmbTipo.getSelectedIndex()-1).getIdTipoMaquina(),  txtDescripcion.getText() , fecha, "1", "1" );
        if(txtIdMaquina.getText().isEmpty()){
           
          
           
            
             System.out.println("efectua la insercion");
            Controlador.Service.Produccion.GestionProduccion.agregarMaquina(nm);
            JOptionPane.showMessageDialog(null,"Se agregó datos");
        
        }else{
            Controlador.Service.Produccion.GestionProduccion.actualizarMaquinas(nm);
            JOptionPane.showMessageDialog(null,"Se actualizó datos");
////////            JOptionPane.showMessageDialog(this,"Se actualizo datos");
        }
           
         tb.actualizarTabla();
        txtIdMaquina.setText("");
        txtNombre.setText("");
        txtDescripcion.setText("");
        cmbTipo.setSelectedIndex(0);
        cmbTipo.setEnabled(true);
            }     
            
      
       
//        dpFecha.setDate(today);
         
        } catch (Exception ex) {
        System.out.println("errror"+ex.getMessage());
        System.out.println("errror"+ex);
        }
        
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        // TODO add your handling code here:zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
        txtIdMaquina.setText("");
        txtNombre.setText("");
        txtDescripcion.setText("");
        cmbTipo.setSelectedIndex(0);
        cmbTipo.setEnabled(true);
        jdpFecha.setDate(today);
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:
        buscarMaquina bM = new buscarMaquina(this);
        Main.getDesktop().add(bM);
        bM.setVisible(true);
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void cmbTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTipoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbTipoActionPerformed

    private void tblMaquinasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblMaquinasMouseClicked
        // TODO add your handling code here:

       try{
           int selectedRowIndex = tblMaquinas.getSelectedRow();
        int selectedColumnIndex = tblMaquinas.getSelectedColumn();
        System.out.println("selectedColumnIndex"+selectedColumnIndex);
        if(selectedColumnIndex!=5){
            String selectId = (String) tblMaquinas.getValueAt(selectedRowIndex, 0);
            if(clic == 1 && selectedId.compareTo(selectId)==0){
                txtIdMaquina.setText((String)tblMaquinas.getValueAt(selectedRowIndex, 0));
                txtNombre.setText((String)tblMaquinas.getValueAt(selectedRowIndex, 1));
                
                txtDescripcion.setText((String)tblMaquinas.getValueAt(selectedRowIndex, 2));
//                System.out.println("Mostrando combo"+Integer.parseInt((String)tblMaquinas.getValueAt(selectedRowIndex, 3)));
//                cmbTipo.setSelectedIndex(Integer.parseInt((String)tblMaquinas.getValueAt(selectedRowIndex, 3)));
                System.out.println("Antes de setear cmbtipo"+tblMaquinas.getValueAt(selectedRowIndex, 3)+(String)tblMaquinas.getValueAt(selectedRowIndex, 3));
//                cmbTipo.setSelectedItem(tblMaquinas.getValueAt(selectedRowIndex, 3));
//                cmbTipo.setName(title);
                String combo = (String)tblMaquinas.getValueAt(selectedRowIndex, 3);
                String pos = (combo.substring(3));
                int valor = Integer.parseInt(pos);
               System.out.println("po......s"+valor);
                cmbTipo.setSelectedIndex(valor);
//                if(combo.equals("TMA000001"))
//                cmbTipo.setSelectedIndex(1);
//                else if (combo.equals("TMA000002"))
//                cmbTipo.setSelectedIndex(2);
//                else
//                cmbTipo.setSelectedIndex(3);
                
                jdpFecha.setDate((Date)tblMaquinas.getValueAt(selectedRowIndex, 4));
//                Date fecNac = tb.data.get(selectedRowIndex).getFecha();
//                dpFecha.setDate(fecNac);
//                dpFecha.setDate(tb.data.get(selectedRowIndex).getFecha());
//                txtIdMaquinas.etText((String)tblMaquinas.getValueAt(selectedRowIndex, 1));
//                
//                dpFecha.getDate((Date)tblMaquinas.getValueAt(selectedRowIndex, 2));
//                txtDescripcion.setText((String)tblMaquinas.getValueAt(selectedRowIndex, 2));
//                txtStockMinimo.setText(((Double)tblMaquinas.getValueAt(selectedRowIndex, 3)).toString());
//                txtCantidad.setText(((Double)tblMaquinas.getValueAt(selectedRowIndex, 4)).toString());
//                cmbTipo.setSelectedItem(tblMaquinas.getValueAt(selectedRowIndex, 5));
//                cmbTipo.setSelectedIndex(Integer.parseInt((String)tblMaquinas.getValueAt(selectedRowIndex, 6)));
                clic = 0;
//                cmbTipo.setEnabled(false);
            }else if(clic == 0){
                selectedId = selectId;
                clic++;
            }else{
                clic = 0;
            }
        }else{
            int confirmado = JOptionPane.showConfirmDialog(this,"¿Desea eliminar el producto?");
            if (confirmado == JOptionPane.OK_OPTION){
                Controlador.Service.Produccion.GestionProduccion.eliminarMaquinas((String)tblMaquinas.getValueAt(selectedRowIndex, 0));
                tb.actualizarTabla();
            }
        }
           
       }
       
       catch(Exception e){
           System.out.println("el error es"+e.getMessage());
           System.out.println("el error es"+e);
       }
           
        
        
    }//GEN-LAST:event_tblMaquinasMouseClicked

    private void jdpFechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jdpFechaActionPerformed
        // TODO add your handling code here:
        Calendar calendarA = jdpFecha.getMonthView().getCalendar();
        Calendar calendarB = jdpFecha.getMonthView().getCalendar();
        // starting today if we are in a hurry
        calendarA.setTime(new Date());
        jdpFecha.getMonthView().setUpperBound(calendarA.getTime());
        calendarB.setTime(today);
//        jdpFecha.getMonthView().setLowerBound(calendarB.getTime());
        
    }//GEN-LAST:event_jdpFechaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JComboBox cmbTipo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private org.jdesktop.swingx.JXDatePicker jdpFecha;
    private javax.swing.JLabel lblDescripcion;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblUm;
    private javax.swing.JPanel pnlProducto;
    private javax.swing.JTable tblMaquinas;
    private javax.swing.JTextArea txtDescripcion;
    private javax.swing.JTextField txtIdMaquina;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables
}
